require 'configatron'
require 'win32/registry'

module Rubicant::DotNet

    class Frameworks
        def self.get_framework()
            ENV['framework'] = 'net35' if ENV['framework'].nil?
            configatron.configure_from_yaml(File.dirname(__FILE__) + '/frameworks.yml') if configatron.frameworks.nil?
            frameworkConfiguration = configatron.frameworks.retrieve(ENV['framework'])
            fail('Requested framework does not exist in configuration') if frameworkConfiguration.nil?
            return Framework.new(frameworkConfiguration)
        end

    end

    class Framework
        attr_reader :framework_dir, :sdk_dir

        def initialize(frameworkConfig)
            framework_key = Win32::Registry::HKEY_LOCAL_MACHINE.open(frameworkConfig.framework_registry_path)
            framework_sdk_key = Win32::Registry::HKEY_LOCAL_MACHINE.open(frameworkConfig.framework_sdk_registry_path)
            begin
                @framework_dir = framework_key.read_s(frameworkConfig.framework_registry_key) + "\\#{frameworkConfig.framework_version}"
                @sdk_dir = framework_sdk_key.read_s(frameworkConfig.framework_sdk_registry_key)
            rescue Win32::Registry::Error
                puts "Either the Framework or the SDK is not installed for #{ENV['framework']}"
            end
        end

    end


end